package com.ywy.chat.controller;

import com.ywy.chat.ChatConstants;
import com.ywy.chat.service.ChatService;
import com.ywy.chat.vo.ChatUser;
import com.ywy.common.rest.Result;
import com.ywy.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 群聊Controller
 *
 * @author ywy
 * @date 2021/12/31 14:57
 */
@RestController
@RequestMapping("/chat")
public class ChatController extends BaseController {
    @Autowired
    private ChatService chatService;

    /**
     * 获取用户信息和群聊信息
     * @return
     */
    @GetMapping("/getMineAndGroupData")
    public Result getMineAndGroupData() {
        // 获取当前用户信息
        ChatUser user = chatService.getCurrentUser();

        // 默认群
        Map<String, Object> group = new HashMap<>();
        group.put("name", "社区群聊");
        group.put("type", "group");
        group.put("avatar", "/images/avatar.png");
        group.put("id", ChatConstants.GROUP_ID);
        group.put("members", 0);

        Map<String, Object> map = new HashMap<>();
        map.put("mine", user);
        map.put("group", group);
        return Result.success(map);
    }

    /**
     * 获取群聊历史聊天记录
     * @return
     */
    @GetMapping("/getGroupHistoryMsg")
    public Result getGroupHistoryMsg() {
        List<Object> messages = chatService.getGroupHistoryMsg(20);
        return Result.success(messages);
    }
}
